// miniprogram/utils/message.js
const request = require('./request')
const BASE_URL = '/message'

/**
 * 获取消息分页
 * @param {*} current 
 * @param {*} size 
 * @returns 
 */
function getMessagePage(readState, current = 1, size = 10) {
  if (!readState)
    readState = ''
  return request.get(BASE_URL + '/page/list', { 
    current, size , readState
  });
};

/**
 * 更新读取状态
 * @param {*} taskId 任务id
 * @param {*} param  参数
 */
function updateReadState(id) {
  // 这里用PUT方式，参数放body
  return request.put(BASE_URL + '/'+ id +'/update/read-state');
}

/**
 * 批量更新读取状态
 * @param {*} taskId 任务id
 * @param {*} param  参数
 */
function batchUpdateReadState() {
  // 这里用PUT方式，参数放body
  return request.put(BASE_URL + '/batch-update/read-state');
}

/**
 * 消息统计(我的消息中已读和未读数)
 * @returns 
 */
function messageStatistics() {
  return request.get(BASE_URL + '/statistics');
};

/**
 * 删除消息(逻辑删除)
 * @param {*} messageId 
 */
function delMessage(messageId) {
  return request.delete(BASE_URL + '/' + messageId);
}

module.exports = { 
  getMessagePage,
  updateReadState,
  batchUpdateReadState,
  messageStatistics,
  delMessage
};